define(function(require, exports, module) {
	/**
	 * @type {String} 空白 GIF 图片
	 */
	exports.blankImg = '',

    /**
     * 当图片加载出现错误时触发该事件。将图片指向默认空白的 gif 图片，以免页面上出现红色的叉叉。
     * 另有 onLoad：事件是当图片加载完成之后触发/onAbort：图片加载的时候，用户点击停止加载图片的触发。
     * @param {Element.Image} img
     * @param {Boolean} isTryReload
     */
	exports.tryReloadImg = function (img, isTryReload) {
	    var oldSrc = img.src;
	    // console.log('不能加载图片' + img.src);
	    img.src = $$.dhtml.blankImg;

		isTryReload && window.setTimeout(function(){
			console.log('重新加载图片');
			img.src = oldSrc;
			img.onerror = null; // 如果移除该句的话则有可能会死循环。
		}, 600);
	}
	
    /**
	    * 淡淡显示的效果。
	    * @param elem {Element} 需要淡入的元素
	    * @param speed {Number} 淡入速度,正整数(可选)
	    * @param opacity {Number} 淡入到指定的透明度,0~100(可选)
	    * @return {Element}
	    */
	    exports.fadeIn = function(elem, speed, opacity){
	            // 若使用 Transition，则参数 speed、opacity 无效，必须通过 CSS 设置动画参数
	            if(isSupportsTransitions){
	                    elem.style.display = 'block';
	                    elem.style.opacity = .6;
	                    setTimeout(function(){ // 不能同步进行，依赖 setTimeout 延时一下
	                            elem.style.opacity = 1;
	                    }, 100);
	            }else{
	            speed   = speed   || 80;
	                    opacity = opacity || 100;

	            //初始化透明度变化值为0
	            var val = 0;
	            var elStyle = elem.style;

	            // 显示元素,并将元素值为0透明度(不可见)
	                    elStyle.opacity = val;
	                    elStyle.display = 'block';

	                    //循环将透明值以5递增,即淡入效果
	                    (function(){
	                            elStyle.opacity = val / 100;
	                            val += 20;
	                            if (val <= opacity) {
	                                    window.setTimeout(arguments.callee, speed);
	                            }
	                    })();
	            }

	        return elem;
	    }

	    /**
	    * 淡淡消失的效果。
	    * @param elem {Element} 需要淡入的元素
	    * @param speed {Number} 淡入速度,正整数(可选)
	    * @param opacity {Number} 淡入到指定的透明度,0~100(可选)
	    */
	    exports.fadeOut = function(elem, speed, opacity){
	            if(isSupportsTransitions){
	                    elem.style.opacity = 0;
	                    setTimeout(function(){
	                            elem.style.display = 'none';
	                    }, 300);
	            }else{
	                    speed   = speed     || 90;
	                    opacity = opacity   || 0;

	                    var val = 100;// 初始化透明度变化值为0
	            var elStyle = elem.style;

	                    (function(){
	                elStyle.opacity = val / 100;
	                            val -= 20;// 循环将透明值以 20 递减,即淡出效果
	                            if (val >= opacity) {
	                                    window.setTimeout(arguments.callee, speed);
	                            }else if (val < 0) {
	                                    elStyle.display = 'none';// 元素透明度为0后隐藏元素
	                            }
	                    })();
	            }
	        return elem;
	    }

	/**
	 * @type {Boolean} 是否支持 CSS3 的 transitions。
	 */
	var isSupportsTransitions;
	module.exports.isSupportsTransitions = isSupportsTransitions = (function () {
	    var b = (document.body || document.documentElement).style;
	    var p = 'transition';
	    if(typeof b[p] == 'string') {return true; }

	    // Tests for vendor specific prop
	    v = ['Moz', 'Webkit', 'Khtml', 'O', 'ms'],
	    p = p.charAt(0).toUpperCase() + p.substr(1);
	    for(var i = 0, j = v.length; i < j; i++) {
	      if(typeof b[v[i] + p] == 'string') {
	      	return true; 
	      }
	    }
	    return false;
	})();


	// function slideByCSS3(el, direction, x, move) {
 //        el.style.webkitTransition = direction + ' ' + '500ms ' + 'linear';
 //        var left = move +'px';
 //        el.style.left = left;
 //    }
	// this.mover.addEventListener("webkitTransitionEnd", function() {
	// 	// Do something now that the transition has ended
	// 	alert(999)
	// }, true);


	var nextFrame = (function() {
	    return window.requestAnimationFrame
			|| window.webkitRequestAnimationFrame
			|| window.mozRequestAnimationFrame
			|| window.oRequestAnimationFrame
			|| window.msRequestAnimationFrame
			|| function(callback) { return window.setTimeout(callback, 17); }
	})();

	// 系统提供的定时器，有撤销。有降级处理的
	var cancelFrame = (function () {
	    return window.cancelRequestAnimationFrame
			|| window.webkitCancelAnimationFrame
			|| window.webkitCancelRequestAnimationFrame
			|| window.mozCancelRequestAnimationFrame
			|| window.oCancelRequestAnimationFrame
			|| window.msCancelRequestAnimationFrame
			|| window.clearTimeout
	})();

	exports.slideX = function(el, offset){
		if(isSupportsTransitions){
	        setTransition(el, .4, 'linear');
	        setTranslateX(el, offset);
		}else{
			var oldLeft = el.getBox(4);// 获取上次 left 的值。
        	classicSlide(el, 'left', oldLeft, offset)
		}
	}

    /**
     * [moveX description]
     * @param  {Element} el [description]
     * @param  {Number} fxTime [description]
     * @param  {String} fxName [description]
     */
    function setTransition(el, fxTime, fxName){
        var transition = '{0}s {1}'.format(fxTime, fxName);

        el.style.webkitTransition = '-webkit-transform ' + transition;
        el.style.transition = 'transform ' + transition;
    }

    /**
     * [setTranslateX description]
     * @param {Element} el [description]
     * @param {Number} x  [description]
     */
    function setTranslateX(el, x){
        var css = 'translateX({0}px)'.format(x);
        el.style.webkitTransform = css;
        el.style.transform = css;
    }

    /**
     * 获取水平的偏移值
     * @param  {Element} el [description]
     * @return {Number}    [description]
     */
    function getLeft(el){
    	var el_Left;
    	var value;

    	if(isSupportsTransitions){
	    	value = el.style.webkitTransform;

			if(!value){
				el_Left = 0;
			}else{
				var getNumberInCSS_Transform = /-?\d+/;
				value = value.match(getNumberInCSS_Transform);
				value = value[0];

				el_Left = Number(value);
			}
    	}else{ // 传统 left/top 位移
			// el.style.top/left只写不适宜读，因为获取回来的值不准确的
			value = window.getComputedStyle(el);
			value = value.left;

			el_Left = window.parseInt(value, 10) || 0;
    	}

		return el_Left;
    }

    exports.getLeft = getLeft;

    /**
     * 平移元素
     * @return {[type]} [description]
     */
    var moveByLeft = isSupportsTransitions ? function moveByLeft(el, leftValue){
		// 要将以像素的单位的改为以百分比为单位@todo
	    el.style.webkitTransition = '-webkit-transform 0s linear';
		el.style.webkitTransform  = 'translateX({0}px)'.format(leftValue);
    } : function moveByLeft(el, leftValue){
    	el.style.left = leftValue + "px";
    }

    exports.moveByLeft = moveByLeft;
});